<template>
<Select v-model="selValue" @on-change="change">
	<Option value="all">请选择</Option>
	<!-- <Option value="all">全选</Option> -->
	<Option v-for="item in list" :value="item[field]" :key="item.id">{{ item.name }}</Option>
</Select>
</template>
<script>
export default {
	data:function(){
		return{		
			list:[],
			selValue:0
		};
	},
	props:{
		value:{
			default:''
		},
		field:{
			default:'id'
		},
		allow_data:{
			type:Array,
			default:function(){
				return [];
			}
		}
	},
	created:function(){
		this.selValue = this.value;
		this.load_data();
	},
	watch:{
		value(val){
			this.selValue = val;
		},
		selValue(val){
			this.$emit('input',val);
		}
	},
	methods:{
		load_data(){
			var self = this;
			var postdata = {};
			
			Whttp.load('User/Currency/get_all',postdata,function(result){
				self.list = [];
				for(var i in result){
					if(self.allow_data.length>0){
						if(self.allow_data.in_array(result[i][self.field])){
							self.list.push(result[i]);
						}
					}
					else{
						self.list.push(result[i]);
					}
				}
			
				
			});
		},
		change(val){
			for(var i=0;i<this.list.length;i++){
				if(this.list[i][this.field]==val){
				
					var ls_val = this._getData(this.list[i]);
					
					this.$emit('change',ls_val);
					break;
				}
			}
			
		}
	}
}
</script>
<style scoped>

</style>